//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Resource Application Block
//===============================================================================

using System;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design;
using EntLibContrib.Resource;

#if !NUNIT
using Microsoft.VisualStudio.TestTools.UnitTesting;
#else
using NUnit.Framework;
using TestClass = NUnit.Framework.TestFixtureAttribute;
using TestInitialize = NUnit.Framework.SetUpAttribute;
using TestCleanup = NUnit.Framework.TearDownAttribute;
using TestMethod = NUnit.Framework.TestAttribute;
#endif

namespace EntLibContrib.Resource.Configuration.Design.Tests
{
	[TestClass]
	public class AssemblyResourceProviderNodeFixture : ConfigurationDesignHost
	{
		private static ResourceManager internalResources = InternalResourceFactory.GetResourceManager();

		[TestMethod]
		[ExpectedException(typeof(ArgumentNullException))]
		public void PassingNullDataInAssemblyResourceProviderThrowsException ()
		{
			new AssemblyResourceProviderNode(null);
		}

		[TestMethod]
		public void EnsureAssemblyResourceProviderNodePropertyCategoriesAndDescriptions ()
		{
			Assert.IsTrue(ResourceAttributesHelper.AssertResourceDescription(typeof(AssemblyResourceProviderNode), "ResourceName", internalResources["AssemblyResourceNameDescription"]));
			Assert.IsTrue(ResourceAttributesHelper.AssertResourceCategory(typeof(AssemblyResourceProviderNode), "ResourceName", internalResources["CategoryProvider"]));
		}

		[TestMethod]
		public void CanCreateAssemblyResourceProviderNodeByDataType ()
		{
			ConfigurationNode node = ServiceHelper.GetNodeCreationService(ServiceProvider).CreateNodeByDataType(typeof(AssemblyResourceProviderData), new object[] { new AssemblyResourceProviderData() });
			Assert.IsNotNull(node);
			Assert.AreEqual(typeof(AssemblyResourceProviderNode), node.GetType());
		}

		[TestMethod]
		public void AssemblyResourceProviderNodeTest ()
		{
			string assemblyResourceProviderName = "AssemblyResourceProvider";
			string resourceAssemblyName = "resourceAssemblyName";
			string resourceBaseName = "resourceBaseName";

			AssemblyResourceProviderNode node = new AssemblyResourceProviderNode();
			node.Name = assemblyResourceProviderName;
			node.ResourceName.AssemblyName = resourceAssemblyName;
			node.ResourceName.BaseName = resourceBaseName;

			Assert.AreEqual(assemblyResourceProviderName, node.Name);
			Assert.AreEqual(resourceAssemblyName, node.ResourceName.AssemblyName);
			Assert.AreEqual(resourceBaseName, node.ResourceName.BaseName);

			AssemblyResourceProviderData data = (AssemblyResourceProviderData)node.ResourceProviderData;
			Assert.AreEqual(assemblyResourceProviderName, data.Name);
			Assert.AreEqual(resourceAssemblyName, data.ResourceAssemblyName);
			Assert.AreEqual(resourceBaseName, data.ResourceBaseName);
		}

		[TestMethod]
		public void AssemblyResourceProviderDataTest ()
		{
			string assemblyResourceProviderName = "AssemblyResourceProvider";
			string resourceAssemblyName = "resourceAssemblyName";
			string resourceBaseName = "resourceBaseName";

			AssemblyResourceProviderData data = new AssemblyResourceProviderData();
			data.Name = assemblyResourceProviderName;
			data.ResourceAssemblyName = resourceAssemblyName;
			data.ResourceBaseName = resourceBaseName;
			Assert.AreEqual(assemblyResourceProviderName, data.Name);
			Assert.AreEqual(resourceAssemblyName, data.ResourceAssemblyName);
			Assert.AreEqual(resourceBaseName, data.ResourceBaseName);

			AssemblyResourceProviderNode node = new AssemblyResourceProviderNode(data);
			Assert.AreEqual(assemblyResourceProviderName, node.Name);
			Assert.AreEqual(resourceAssemblyName, node.ResourceName.AssemblyName);
			Assert.AreEqual(resourceBaseName, node.ResourceName.BaseName);
		}
	}
}